pub mod config;
pub mod util;
pub mod c;
pub mod argument;
mod build_service;

use crate::argument::Argument;
use crate::build_service::BuildService;
use crate::config::Config;
use crate::util::Util;
use clap::Parser;
use proto::build_node::build_hot_update_service_server::{BuildHotUpdateService, BuildHotUpdateServiceServer};
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use tonic::transport::Server;
use tracing_subscriber::util::SubscriberInitExt;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    share::util::init_log(
        &Util::app_dirs().data_dir().join("log")
    );

    let arg = Argument::parse();
    let config = Config::with_argument(&arg);

    let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), config.port().clone());

    let service = BuildService::new();

    Server::builder()
        .add_service(BuildHotUpdateServiceServer::new(service))
        .serve(addr)
        .await?;

    Ok(())
}
